package com.swind.fast.modules.app.halali.partner.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.swind.fast.common.api.vo.Result;
import com.swind.fast.common.system.query.QueryGenerator;
import com.swind.fast.common.util.oConvertUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.swind.fast.common.system.base.controller.SwindController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.swind.fast.modules.app.halali.partner.vo.request.HomeRequest;
import com.swind.fast.modules.app.halali.partner.vo.response.PartnerHomeVo;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantMeal;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealService;
import com.swind.fast.modules.app.halali.partner.entity.Restaurant;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantService;

import com.swind.fast.modules.app.halali.partner.component.FrontComponent;
import com.swind.fast.common.system.vo.HalaliLoginUser;
import org.apache.shiro.SecurityUtils;
import com.swind.fast.modules.app.halali.partner.entity.RestaurantOperation;

 /**
 * @Description: 用户端
 * @Author: swind
 * @Date:   2022-01-20
 * @Version: V1.0
 */
@Api(tags="02.商户端-首页")
@RestController
@RequestMapping("/app/partner/front")
@Slf4j
public class FrontController {

    @Autowired
    private FrontComponent frontComponent;

    @Autowired
    private IRestaurantService restaurantService;

    /**
     * 首页数据
     *
     * @param req
     * @return
     */
    @ApiOperation(value="首页-数据", notes="")
    @GetMapping(value = "/home")
    public Result<PartnerHomeVo> homeAction() {
        HalaliLoginUser sysUser = (HalaliLoginUser) SecurityUtils.getSubject().getPrincipal();
        log.info("sysUser: {}", sysUser);

        RestaurantOperation operation = restaurantService.getOperationById(sysUser.getRestaurantId());
        log.info("operation: {}", operation);

        PartnerHomeVo result = restaurantService.getHomeResult(sysUser.getRestaurantId());

        return Result.OK("成功!", result);
    }

    // @ApiOperation(value="首页 - 搜索菜品", notes="首页 - 搜索菜品")
    // @GetMapping(value = "/search")
    // public Result<?> searchAction() {
    //     HomeResponse response = new HomeResponse();

    //     List<Restaurant> restaurants = restaurantService.list();
    //     response.setRestaurants(restaurants);

    //     return Result.OK("成功!", response);
    // }
}
